
--注册常规合成
register_crad_rule('史莱克七怪',{'蓝银草','九宝琉璃塔','香肠','幽冥灵猫','邪眸白虎','柔骨兔','邪火凤凰'})
register_crad_rule('武魂殿',{'鬼斗罗','菊斗罗','千道流','胡列娜','千仞雪','比比东'})


--入口
local mt = ac.skill['蓝银草']
local crads = {
    '蓝银草',
    '九宝琉璃塔','香肠','幽冥灵猫','邪眸白虎','柔骨兔','邪火凤凰',
    '鬼斗罗','菊斗罗','千道流','胡列娜','千仞雪','比比东',
}
function mt:on_card(hero,player)
    if hero[self.name] then
        return
    end
    hero[self.name] = true
    for _,name in ipairs(crads) do
        player:set_data(name,true)
    end

    player:event '卡池-添加卡组'(function(_,_,pool)
        for _,name in ipairs(crads) do
            pool[#pool+1] = name
        end
    end)
    hero:event '天赋-检测合成后'(function(trg)
        local haves = hero:get_data('拥有天赋表') or {}
        for _,name in ipairs(crads) do
            if not haves[name] then
                return
            end
        end
        trg:remove()
        hero:set_data('完成-计数',hero:get_data('完成-计数',0) + 1)
    end)
end

local mt = ac.skill['吃香肠']
mt.model1 = [[d79b6e36b5388413f69854db3a90e320.mdl]]
function mt:on_card(hero,player)
    self:gc(ac.loop(self.data1 * 1000,function()
        hero:add_effect(self.model1):remove()
        hero:add('生命',(hero:get('生命上限') - hero:get('生命'))*self.data2 / 1000)
    end))
end


local mt = ac.skill['八段摔']
mt.temp = '攻击计数'
mt.count = 8
function mt:on_init(hero,target)
    self.count = self.data1
end

function mt:on_run(hero,target)
    local hero = self.owner
    local count = self.data2
    local group = ac.selector('unit'):range(hero,600):enemy(hero):get()
    for a,u in ipairs(table.random_table(group,count)) do
        ac.wait(a*200,function()
            local damage = hero:get(self['属性1']) * self.data3 / 100
            local point1 = hero:get_point()
            local point2 = u:get_point()
            local angle = point1/point2
            local point3 = point2 - {angle,100}
            local effect = point3:effect{
                model = hero:get_model(),
                hide_when_remove = true,
                angle = angle + 180,
                speed = 2,
                time = 0.7,
            }
            effect:play_animation('attack')
            effect:set_color(50,50,50,100)
            hero:create_damage(u,damage,self)
        end)
    end
end


local mt = ac.skill['凤凰啸天击']
mt.model1 = [[69793e64295953d0b8f55f72233a46fa.mdl]]
function mt:on_add()
    local hero = self.owner
    self:gc(hero:event '单位-造成伤害'(function(_,_,target,data)
        if data.skill and data['暴击'] then
            local damage = hero:get(self['属性1']) * self.data1 / 100
            local point = target:get_point()
            point:add_effect(self.model1):remove()
            for u in ac.selector('unit')
                : range(point,300)
                : enemy(hero)
                : loop()
            do
                u:damage{
                    source = hero,
                    damage = damage,
                    skill = self,
                    ['附加'] = true,
                }
            end

        end
    end))
end



local mt = ac.skill['七怪同心']
function mt:on_add()
    local hero = self.owner
    local count = 0
    self:gc(hero:event '单位-造成伤害'(function(_,_,target,data)
        if data:is_attack() then
            local damage = hero:get('攻击') * self.data1 / 100
            for u in ac.selector('unit')
                : range(target,400)
                : is_not(target)
                : enemy(hero)
                : loop()
            do
                --u:add_effect(self.model,'chest'):remove()
                u:damage{
                    damage_type = '真实',
                    source = hero,
                    damage = damage,
                    skill = self,
                }
            end
        end
    end))
end

local mt = ac.skill['武魂共鸣']
function mt:on_add()
    local hero = self.owner
    local count = 0
    self:gc(hero:event '单位-击杀'(function(_,_,target)
        count = count + 1
        if count>=self.data1 then
            hero:add('魔法',self.data2)
        end
    end))
end

local mt = ac.skill['海神祝福']
mt.temp = '攻击计数'
mt.count = 3
mt.model1 = [[ee57c4ac537e8076c623dbe6bc75e317.mdl]]
function mt:on_init()
    local hero = self.owner
    self.count = self.data1
    self:gc(hero:event '单位-攻击命中'(function(_,_,target)
        if target:get('当前生命百分比')>80 and target['史莱克七怪-破甲']==nil then
            target['史莱克七怪-破甲'] = true
            target:add_buff '史莱克七怪-破甲'{}
        end
    end))
end

function mt:on_run(hero,target)
    local hero = self.owner
    local damage = hero:get(self['属性1']) * self.data2 / 100
    local point = target:get_point()
    point:effect{
        model = self.model1,
        size = 2,
        time = 1,
    }
    ac.wait(1000,function()
        hero:aoe_damage(target,600,damage,self)
    end)
end



local buff = ac.buff['史莱克七怪-破甲']
buff.time = 10

function buff:on_add()
    self:gc(self.owner:add_effect([[6c10a3376824c094388be227c9b85bf3.mdl]],'overhead'))
    self:gc(self.owner:add('额外护甲',-30))
end



local mt = ac.skill['天使审判']
mt.temp = '攻击触发'
mt.cool = 6
mt.model1 = [[94d3318d35f5d6afd522b273c08652b3.mdl]]
function mt:on_init()
    self.cool = self.data1
end

function mt:on_run(hero,target)
    local hero = self.owner
    local damage = hero:get(self['属性1']) * self.data3 / 100 + hero:get(self['属性2']) * self.data4 / 100
    local point = target:get_point()
    point:effect{
        model = self.model1,
        size = 2,
        time = 0.2,
    }
    hero:aoe_damage(target,self.data2,damage,self)
end



local mt = ac.skill['罗刹真身']
mt.temp = '攻击触发'
mt.cool = 60
mt.model1 = [[Abilities\Spells\Undead\DeathCoil\DeathCoilMissile.mdl]]
mt.model2 = [[00c143ec83d800af5ba96bc8caa98de3.mdl]]

function mt:on_run(hero,target)
    local hero = self.owner
    local event = hero:event '单位-攻击命中'(function(_,_,target)
        local damage = hero:get(self['属性1']) * self.data2 / 100
        for u in ac.selector('unit')
            : range(target,800)
            : enemy(hero)
            : loop()
        do
            hero:launch_missile(u,self.model2,900,0.15,function()
                hero:create_damage(u,damage,self)
            end)
        end

    end)
    ac.wait(self.data1 * 1000,function()
        event:remove()
    end)
end


local mt = ac.skill['天使圣裁']
function mt:on_add()
    local hero = self.owner
    self:gc(hero:event '单位-造成伤害'(function(_,_,target,data)
        if target:is_type('精英') then
            data:mul(self.data1)
        end
    end))
    local count = 0
    self:gc(hero:add_buff(self.name){
        art = self.art,
        tip = self:get_tip(),
        keep = true,
        on_add = function(buff)
            buff:gc(hero:event '单位-击杀'(function(_,_,target,data)
                if target:is_type('精英') then
                    count = count + 1
                    if count<=self.data3 then
                        buff.stack = count
                        hero:add(self['属性1'],self.data2)
                    end
                end
            end))
        end
    })
end

local mt = ac.skill['吞魂']
function mt:on_add()
    local hero = self.owner
    self:gc(hero:event '单位-击杀'(function(_,_,target,data)
        if target:is_type('精英') then
            hero:add('基础智力',self.data1)
        end
    end))
end


local mt = ac.skill['蓝银缠绕']
mt.temp = '攻击触发'
mt.model1 = [[Abilities\Weapons\KeeperGroveMissile\KeeperGroveMissile.mdl]]
mt.model2 = [[Abilities\Spells\NightElf\EntanglingRoots\EntanglingRootsTarget.mdl]]
function mt:on_run(hero,target)
    local group = ac.selector('unit'):range(target,600):enemy(hero):get(4)
    local damage = hero:get('攻击') * self.data1/100 + hero:get('智力') * self.data2/100
    for _,unit in ipairs(group) do
        hero:launch_missile(unit,self.model1,900,0.15,function()
            unit:add_buff '蓝银缠绕'{
                time = self.data3,
                on_add = function(buff)
                    unit:add_restriction '定身'
                    buff:gc(unit:add_effect(self.model2))
                    buff:gc(function()
                        unit:remove_restriction '定身'
                    end)
                end,
            }
            hero:create_damage(unit,damage,self)
        end)
    end
end

local mt = ac.skill['六翼天使']

function mt:on_add()
    local hero = self.owner
    local count = 0
    self:gc(ac.loop(1000,function()
        count = count + self.data1
        hero:add('法爆几率',self.data1)
    end))
    self:gc(hero:event '单位-即将造成伤害'(function(_,_,_,data)
        if data['暴击'] and data.damage_type=='魔法' then
            hero:add('法爆几率',- count)
            count = 0
        end
    end))
    self:gc(function()
        hero:add('法爆几率',- count)
    end)
end


local mt = ac.skill['白虎烈光波']

function mt:on_add()
    local hero = self.owner
    self:gc(hero:event '单位-即将造成伤害'(function(_,_,_,data)
        if data['暴击'] and data.damage_type=='魔法' then
            hero:add_buff(self.name){
                art = self.art,
                tip = '伤害增幅提升',
                time = 2,
                stack = 0,

                on_add = function(buff)
                    buff.stack = buff.stack + 1
                    buff:gc(hero:add('伤害增幅',self.data1))
                end,

                on_cover = function(buff)
                    buff:set_remaining(buff.time)
                    if buff.stack<self.data2 then
                        buff:on_add()
                    end
                    return false
                end
            }
        end
    end))
end